<?php

namespace Modules\Asset\Http\Controllers\Admin\V1;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;

use \Modules\Asset\Entities\Asset;
use \Modules\Asset\Entities\AssetRecord;

use Validator;
use ThrowException;
use Auth;

class AssetController extends Controller
{
    public function show(Request $req, $assetType)
    {
        $rule = [
        ];

        Validator::make($req->all(), $rule)->fails() && ThrowException::BadRequest();

        $admin = Auth::requireLoginAdmin();

        $info = [
            'balance' => Asset::where('type', $assetType)->sum('balance'),
            'in' => AssetRecord::assetType($assetType)->type('in')->sum('value'),
            'out' => AssetRecord::assetType($assetType)->type('out')->sum('value'),
        ];

        return [
            'info' => $info
        ];
    }
}
